import 'package:flutter/material.dart';

class LinearGradientText extends StatelessWidget {
  final String text;
  final TextStyle style;
  final TextAlign? textAlign;

  final bool isHorizontal;
  final List<Color> gradientColors;
  final List<double>? stops;

  LinearGradientText({
    super.key,
    required this.text,
    this.isHorizontal = true,
    required this.gradientColors,
    this.stops,
    double fontSize = 16,
    FontWeight fontWeight = FontWeight.w600,
    double height = 1,
    TextStyle? style,
    this.textAlign,
  }) : style = style ?? TextStyle(fontSize: fontSize, fontWeight: fontWeight, height: height);

  @override
  Widget build(BuildContext context) {
    return ShaderMask(
      shaderCallback: (bounds) {
        return LinearGradient(
                colors: gradientColors, stops: stops, begin: isHorizontal ? Alignment.centerLeft : Alignment.topCenter, end: isHorizontal ? Alignment.centerRight : Alignment.bottomCenter)
            .createShader(bounds);
      },
      child: Text(text, textAlign: textAlign, style: style.copyWith(color: Colors.white)),
    );
  }
}
